//
//  FourthTextViewController.m
//  iosStudyText
//
//  Created by wangning on 15/8/14.
//  Copyright (c) 2015年 mohekeji. All rights reserved.
//

#import "FourthTextViewController.h"
#import "FourthTextWebViewController.h"
//考试第三题
#define IP 4;
#define Height 40;

@interface FourthTextViewController ()<UIAlertViewDelegate>

@end

@implementation FourthTextViewController
//考试的第一题
//页面将要出现
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
}
//页面已经出现
- (void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
}
//页面将要消失
- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
}
//页面已经消失
- (void)viewDidDisappear:(BOOL)animated{
    [super viewDidDisappear:animated];
}
//页面已经加载
- (void)viewDidLoad {
    [super viewDidLoad];
//考试第五题 全局断点已经打开
    
    //考试第七题——手写josh，绘制数据源
    _mainArr = @[
                @{
                    @"header": @"我是headerOne",
                    @"footer": @"我是footerOne",
                    @"list": @[
                            @{
                                @"title": @"我是titleOne",
                                @"content": @"我是contentOne"
                                },
                            @{
                                @"title": @"我是titleOne的other",
                                @"content": @"我是contentOne的other"
                                }
                            ]
                    },
                @{
                    @"header": @"我是headerTow",
                    @"footer": @"我是footerTow",
                    @"list": @[
                            @{
                                @"title": @"我是titleTow",
                                @"content": @"我是contentTow"
                                },
                            @{
                                @"title": @"我是titleTow的other",
                                @"content": @"我是contentTow的other"
                                }
                            ]
                    }
                ];
    
    
    
    //考试第四题——UserDefault运用
    [[NSUserDefaults standardUserDefaults] setObject:@"张鑫培" forKey:@"named"];
    NSString *name=  [[NSUserDefaults standardUserDefaults] valueForKey:@"named"];
    NSLog(@"%@\n",name);
    [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"named"];
    NSString *name1=  [[NSUserDefaults standardUserDefaults] valueForKey:@"named"];
    NSLog(@"%@\n",name1);
    
    //考试第六题——三目运算符
    int i=3,j=4;
    NSString *arrTow =i>j?@"right":@"error";
    NSLog(@"%@\n",arrTow);
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
//考试第八题——绘制tableView
//section的数量
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    
    return _mainArr.count;
}
//header的绘制
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UIView *headerView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 320, 59)];
    headerView.backgroundColor = [UIColor orangeColor];
    
    NSDictionary *dicOne = [_mainArr objectAtIndex:section];
    UILabel *headerTitleLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, 10, 200, 21)];
    headerTitleLabel.text = dicOne[@"header"];
    headerTitleLabel.font = [UIFont systemFontOfSize:15];
    
    [headerView addSubview:headerTitleLabel];
    
    return headerView;
}

//header的高度
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return Height;
}

//footer的绘制
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    UIView *footerView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 320, 59)];
    footerView.backgroundColor = [UIColor greenColor];
    
    NSDictionary *dicTow = [_mainArr objectAtIndex:section];
    UILabel *footerTitleLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, 10, 200, 21)];
    footerTitleLabel.text = dicTow[@"footer"];
    footerTitleLabel.font = [UIFont systemFontOfSize:15];
    
    
    [footerView addSubview:footerTitleLabel];
    return footerView;
}

//footer的高度
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return Height;
}

//cell的个数
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    NSDictionary *dicThree = [_mainArr objectAtIndex:section];
    NSArray *arrOne = dicThree[@"list"];
    return arrOne.count;
}

//cell的高度
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 59;
    
}

//cell的绘制
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *cellIdentifier = @"Mycell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (cell==nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIdentifier];
    }
    
    NSDictionary *dicTow = [_mainArr objectAtIndex:indexPath.section];
    NSArray *arrTow = [dicTow objectForKey:@"list"];
    NSDictionary *dicThree = [arrTow objectAtIndex:indexPath.row];
    cell.textLabel.text = dicThree[@"title"];
    cell.detailTextLabel.text = dicThree[@"content"];
    
    return cell;
}
//考试第二题——绘制
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"警告" message:@"您是否要跳转到Web" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:@"取消", nil];
    [alert show];
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
    
    if (buttonIndex == 0) {
        FourthTextWebViewController *to = [[FourthTextWebViewController alloc]init];
        [self.navigationController pushViewController:to animated:YES];
    }
}
    


/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
